home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 552 < prev    next >
Encoding:
Text File  |  1996-08-06  |  2.8 KB  |  63 lines

  1. Path: chronicle.mti.sgi.com!austern
  2. From: James Kanze US/ESC 60/3/141 #40763 <kanze@lts.sel.alcatel.de>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: The realloc question: rationale?
  5. Date: 26 Feb 1996 11:48:32 PST
  6. Organization: -
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <9602261740.AA28201@lts.sel.alcatel.de>
  9. References: <4g903m$7g8@mari.onr.com> <4gl2ad$lqi@hermes.synopsys.com> <31301BFE.450A@onr.com> <xsod973w4m5.fsf@glob.cs.rpi.edu>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: Mon, 26 Feb 96 18:40:08 +0100
  12. In-Reply-To: vandevod@cs.rpi.edu's message of 26 Feb 1996 01:33:33 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMTIOpUy4NqrwXLNJAQG8mwH/Qr2+pincVvpog44bxi2ngO8ycJ6S9Il5
  15.     MQeEaRtK7pZl8gvhNWydFi1p489OFMDaTmP2ZTML9HR7yjrDAZ70zw==
  16.     =gs+6
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <xsod973w4m5.fsf@glob.cs.rpi.edu> vandevod@cs.rpi.edu
  20. (David Vandevoorde) writes:
  21.  
  22. |> >>>>> "KK" == Kerry Kimbrough <kk@onr.com> writes:
  23. |> KK> Joe Buck wrote:
  24. |> KK>>  You can, of course, call the C realloc().
  25.  
  26. |> KK> But then crash? My understanding is that mixture of alloc/free and
  27. |> KK> friends with new/delete is not guaranteed to be valid and
  28. |> KK> therefore is discouraged.  Not true?
  29. |> [...]
  30.  
  31. |> Since you can provide your own new operators etc., you can ensure that
  32. |> it's safe to use realloc with new/delete (or you can provide a function
  33. |> based on realloc with similar functionality).
  34.  
  35. I don't think you can make it safe even providing your own operator
  36. new/delete (or rather operator new[]/delete[], since realloc only
  37. makes sense on arrays).  There are two problems:
  38.  
  39. 1. It is, in fact, impossible to obtain the address actually returned
  40. by operator new[].  The implementation is allowed to (and most do) ask
  41. for extra memory in order to maintain the number of elements.
  42. Typically, this memory will be in front of the first element, so the
  43. compiler will `fix up' the address returned by operator new[] before
  44. you ever see it.
  45.  
  46. 2. The implementation is allowed to save this address in some sort of
  47. cache.  For example, an alternate implementation of a new expression
  48. for an array would be for the implementation to maintain an
  49. associative array of addresses to counts.
  50.  
  51. --
  52. James Kanze         Tel.: (+33) 88 14 49 00        email: kanze@gabi-soft.fr
  53. GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
  54. Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
  55.                 -- A la recherche d'une activitΘ dans une region francophone
  56. ---
  57. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  58.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  59.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  60.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  61.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  62. ]
  63.